import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

async function main(): Promise<void> {
  const top = await prisma.userStaking.findMany({
    orderBy: [
      { dailyRewardRate: 'desc' },
      { stakedAmount: 'desc' }
    ],
    take: 10,
    include: {
      user: {
        select: {
          idNumber: true,
          name: true,
          tier: true,
          createdAt: true
        }
      }
    }
  })

  top.forEach((item) => {
    console.log({
      userId: item.userId,
      idNumber: item.user.idNumber,
      name: item.user.name,
      tier: item.user.tier,
      createdAt: item.user.createdAt.toISOString(),
      stakedAmount: Number(item.stakedAmount),
      lockedAmount: Number(item.lockedAmount),
      dailyRewardRate: Number(item.dailyRewardRate),
      currentDailyReward: Number(item.currentDailyReward),
      totalRewardsNear: Number(item.totalRewardsNear)
    })
  })
}

main()
  .catch((error) => {
    console.error(error)
    process.exitCode = 1
  })
  .finally(async () => {
    await prisma.$disconnect()
  })
